#!/usr/bin/python
#oracle_RF
import re
import os
import sys

debug = False

lines = sys.stdin.readlines()

lemma = sys.argv[1]
if debug: print >> sys.stderr, "Lemma is "+lemma

priorities = []

def prioritize(num,m):
  global priorities, plist, match
  for i in range(len(priorities)):
    if match:
      if re.match(priorities[i],m):
         plist[i].append(num)
         break
    else:
      if priorities[i] in m:
         plist[i].append(num)
         break

if lemma == "secret_x":
  match = False
  priorities = ["~~>","AgSt","cp(", "In_S","In_A","~~>","cp("]

if lemma == "secret_r":
  match = False
  priorities = ["~~>","AgSt","cp(", "In_S","In_A","~~>","cp("]

if lemma == "secret_rb":
  match = False
  priorities = ["~~>","AgSt","cp(", "In_S","In_A","~~>","cp("]

if lemma == "secret_vote":
  match = False
  priorities = ["~~>","AgSt","cp(", "In_S","In_A","~~>","cp("]

if lemma == "agreementHwrtS":
  match = False
  priorities = ["~~>","AgSt","In_S","In_A","cp("]

if lemma == "agreementAwrtS":
  match = False
  priorities = ["~~>","AgSt","In_S","In_A","cp("]

if lemma == "agreementSwrtH_vote":
  match = False
  priorities = ["In_S","In_A","!KU( ~r1","!KU( ~rb1","!KU( ~skS","!KU( h(","~~>","AgSt","In_S","In_A","cp("]

if lemma == "agreementSwrtH_code":
  match = False
  priorities = ["In_S","In_A","!KU( ~r1","!KU( ~rb1","!KU( ~skS","!KU( h(","~~>","AgSt","In_S","In_A","cp("]

if lemma == "indivVerif":
  match = False
  priorities = ["AgSt_H","In_A( 'S', <'codes'","In_A( 'BB', <'codes'","In_S","In_A","In_S( 'H1'","~~>","cp("]


if lemma == "Observational_equivalence":
  match = False
  priorities = ["'proofV'","In_S","_BB0","Out_A( $A, x","!KD( $ind","~~>", "!KU( $ind","In_S", "KU( ~skS","KU( ~x","KU( h(~x","h(<~x", "h(<'H2', ~x","h(<'H2', ~x","h(<'H1', ~x", "KD(", "!KU( 'BB'", "!KD( 'BB'", "!KU( PeqPV","'pVHashes'", "!KU( x )",
 "!KU( 'codes'"]
#if lemma == "Device_authentication":
#  match = False
#  priorities = [ "AgentState", "senc", "~skS.3", "~skS.1", "~rD.1", "~rS.1", "~pw", "~rS", "~rD" ]

#j
plist = [ [] for i in priorities ]

for line in lines:
  if debug: print >> sys.stderr, "Line is "+line,

  num = line.split(':')[0]

#  if lemma == "secret":
  prioritize(num,line)
#    if debug: print >> sys.stderr, "Current list: ",plist
#  else:
#    sys.exit(0)

for j in range(len(plist)):
  for i in plist[j]:
    print i
#print 1
